package com.coincalf.wallet.blockchain;

import com.coincalf.framework.enums.TxStateEnum;
import com.coincalf.wallet.blockchain.bean.TransInfo;
import com.coincalf.wallet.blockchain.bean.trx.*;
import com.coincalf.wallet.blockchain.client.TrxUrlClient;
import com.coincalf.wallet.blockchain.util.AESUtil;
import com.coincalf.wallet.blockchain.util.HttpUtil;
import com.coincalf.wallet.blockchain.util.JsonUtils;
import com.google.protobuf.Any;
import com.google.protobuf.ByteString;
import com.google.protobuf.InvalidProtocolBufferException;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.bitcoinj.core.Base58;
import org.bouncycastle.util.encoders.Hex;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import org.tron.common.crypto.ECKey;
import org.tron.common.crypto.Sha256Sm3Hash;
import org.tron.common.utils.ByteArray;
import org.tron.protos.Protocol;
import org.tron.protos.contract.BalanceContract;
import org.tron.protos.contract.SmartContractOuterClass;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.RoundingMode;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * 波场需要大于等于19个区块确认,才算交易确认
 */
@Slf4j
@Component
public class TrxService {

    //TRX节点URL
//    private static String TRX_URL = coinClient.selectRpcServerUrl("XRP");
    //    private static String TRX_URL = "http://13.124.62.58:8090";// 这是公共节点


    public static final String USDT_TRC20_ADDRESS = "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t";

    public static final BigDecimal TRX2SUN = BigDecimal.valueOf(1000000L);

    //TRC20 transfer方法固定值
    public static final String TRC20_TRANSFER_HEX = "a9059cbb";
    //41a614f803b6fd780986a42c78ec9c7f77e6ded13c

    /****************************************交易签名**************************************/

    public Protocol.Transaction setReference(Protocol.Transaction transaction, long blockHeight, byte[] blockHash) {
        byte[] refBlockNum = ByteArray.fromLong(blockHeight);
        Protocol.Transaction.raw rawData = transaction.getRawData().toBuilder()
                .setRefBlockHash(ByteString.copyFrom(ByteArray.subArray(blockHash, 8, 16)))
                .setRefBlockBytes(ByteString.copyFrom(ByteArray.subArray(refBlockNum, 6, 8)))
                .build();
        return transaction.toBuilder().setRawData(rawData).build();
    }

    //广播区块
    public boolean broadcastTx(Protocol.Transaction tx) {
        String s = HttpUtil.doPost(TrxUrlClient.getTrxCLient() + "/wallet/broadcasttransaction", JsonUtils.writeValueAsString(tx));
        return Boolean.getBoolean(s);
    }

    //广播区块  broadcasthex
    public String broadcastTx2(String tx) {
        Map<String, Object> params = new LinkedHashMap<>(4);
        params.put("transaction", tx);
        String result = HttpUtil.doPost(TrxUrlClient.getTrxCLient() + "/wallet/broadcasthex", JsonUtils.writeValueAsString(params));
        return result;
    }

    private Protocol.Transaction signTransaction2Object(byte[] transaction, byte[] privateKey)
            throws InvalidProtocolBufferException {
        ECKey ecKey = ECKey.fromPrivate(privateKey);
        Protocol.Transaction transaction1 = Protocol.Transaction.parseFrom(transaction);
        byte[] rawdata = transaction1.getRawData().toByteArray();
        byte[] hash = Sha256Sm3Hash.hash(rawdata);
        byte[] sign = ecKey.sign(hash).toByteArray();
        return transaction1.toBuilder().addSignature(ByteString.copyFrom(sign)).build();
    }

    public String base58Check2Hex2(String input) {
        return Hex.toHexString(this.base58Check2Hex(input));
    }

    /**
     * base58check格式地址转换为16进制格式
     *
     * @param input 16进制格式地址
     * @return 16进制格式地址
     */
    public byte[] base58Check2Hex(String input) {
        byte[] decodeCheck = org.tron.common.utils.Base58.decode(input);
        if (decodeCheck.length <= 4) {
            throw new RuntimeException("地址格式转换异常");
        }
        byte[] decodeData = new byte[decodeCheck.length - 4];
        System.arraycopy(decodeCheck, 0, decodeData, 0, decodeData.length);
        byte[] hash0 = Sha256Sm3Hash.hash(decodeData);
        byte[] hash1 = Sha256Sm3Hash.hash(hash0);
        if (hash1[0] == decodeCheck[decodeData.length]
                && hash1[1] == decodeCheck[decodeData.length + 1]
                && hash1[2] == decodeCheck[decodeData.length + 2]
                && hash1[3] == decodeCheck[decodeData.length + 3]) {
            return decodeData;
        }
        throw new RuntimeException("地址格式转换异常");
    }

    /**
     * 16进制格式地址转换为base58check格式
     *
     * @param hexStr 16进制地址
     * @return base58check格式地址
     */
    public String hexString2Base58check(String hexStr) {
        byte[] input = Hex.decode(hexStr);
        byte[] hash0 = Sha256Sm3Hash.hash(input);
        byte[] hash1 = Sha256Sm3Hash.hash(hash0);
        byte[] inputCheck = new byte[input.length + 4];
        System.arraycopy(input, 0, inputCheck, 0, input.length);
        System.arraycopy(hash1, 0, inputCheck, input.length, 4);
        return Base58.encode(inputCheck);
    }

    public TransInfo query(String txId) {
        TransInfo response = new TransInfo();
        TrxTxInfo tx = this.queryTxInfo(txId);
        if (tx != null) {
            String result = tx.getResult();
            if (StringUtils.isNotBlank(result) && "FAILED".equals(result)) {
                response.setStatus(TxStateEnum.FAIL.getStatus());
                response.setErrMsg(tx.getReceipt().getResult());
                return response;
            }
            //TODO 交易状态判断待定
            //区块高度确认数
            long confirmations = this.getNowBlockHeight() - tx.getBlockNumber();
            if (confirmations > 18) {
                //交易确认数量大于18 直接设置成功
                response.setStatus(TxStateEnum.SUCCESS.getStatus());
            } else {
                log.info("TRX或者TRC20交易确认数不足18 等待区块确认 txHash={}", txId);
                response.setStatus(TxStateEnum.TO_BE_CONFIRMED.getStatus());
            }
        } else {
            response.setStatus(TxStateEnum.TO_BE_CONFIRMED.getStatus());
        }
        return response;
    }

    /**
     * 查询交易详情
     * <p>
     * 失败的交易  c167c7190b74be6ba3a06a1a2d7780bd91886f5b7af92f323667a11f2d6f452d
     * 86ee0c020ae9540bed4a53b705cba6d4c64060a6e10a91e9c51da9c84f971f01
     *
     * @param txId 交易id
     * @return
     */
    public TrxTransaction queryTx(String txId) {
        Map<String, String> params = new HashMap<>(1);
        params.put("value", txId);
        String result = HttpUtil.doPost(TrxUrlClient.getTrxCLient() + "/wallet/gettransactionbyid", JsonUtils.writeValueAsString(params));
        return JsonUtils.convertValue(result, TrxTransaction.class);
    }

    /**
     * 查询交易详情 包括区块高度以及能量等信息
     *
     * @param txId 交易id
     * @return
     */
    public TrxTxInfo queryTxInfo(String txId) {
        Map<String, String> params = new HashMap<>(1);
        params.put("value", txId);
        String result = HttpUtil.doPost(TrxUrlClient.getTrxCLient() + "/wallet/gettransactioninfobyid", JsonUtils.writeValueAsString(params));
        return JsonUtils.convertValue(result, TrxTxInfo.class);
    }

    /**
     * 获取最新区块信息
     *
     * @return
     */
    public TrxBlock getNowBlock() {
        String blockStr = HttpUtil.doPost(TrxUrlClient.getTrxCLient() + "/wallet/getnowblock", "");
        return JsonUtils.convertValue(blockStr, TrxBlock.class);
    }

    /**
     * 获取TRX最新区块高度
     *
     * @return
     */
    public long getNowBlockHeight() {
        return this.getNowBlock().getBlockHeader().getRawData().getNumber();
    }

    /**
     * 获取TRX指定高度范围内的区块信息
     * 注意:start不能等于end 否则返回{} 即没有任何数据 因为不包括end优先于包括start
     *
     * @param start 开始区块高度(包括)
     * @param end   结束区块高度(不包括)
     * @return
     */
    public static TrxBlocks getBlocks(long start, long end) {
        Map<String, Long> params = new HashMap<>(2);
        params.put("startNum", start);
        params.put("endNum", end);
        String blocksStr = HttpUtil.doPost(TrxUrlClient.getTrxCLient() + "/wallet/getblockbylimitnext", JsonUtils.writeValueAsString(params));
        return JsonUtils.convertValue(blocksStr, TrxBlocks.class);
    }

    public TransInfo sendTrx(TransInfo request) {
        String prk = AESUtil.decrypt(request.getPrivateKey(), BlockConstant.AES_KEY);
        request.setPrivateKey(prk);
        BroadcastResponse response;
        try {
            log.info("TRX提币交易即将执行转账操作 from={}  to={} amount={}", request.getFromAddress(), request.getToAddress(), request.getAmount());
            response = this.sendTrx(request.getFromAddress(), request.getPrivateKey(), request.getToAddress(), request.getAmount());
            log.info("TRX提币交易转账执行结果={}", response.toString());
            if (response.getResult()) {
                request.setTxHash(response.getTxId());
                request.setStatus(TxStateEnum.TO_BE_CONFIRMED.getStatus());
            } else {
                request.setErrMsg(response.getMessage());
                request.setStatus(TxStateEnum.FAIL.getStatus());
            }
        } catch (Exception e) {
            request.setErrMsg(e.getMessage());
            request.setStatus(TxStateEnum.FAIL.getStatus());
        }
        return request;
    }

    /**
     * TRX转账
     *
     * @param fromAddress 转账地址
     * @param fromPrk     转账地址私钥
     * @param toAddress   收款地址
     * @param amount      转账数量 单位:TRX
     * @return
     */
    public BroadcastResponse sendTrx(String fromAddress, String fromPrk, String toAddress, BigDecimal amount) {
        amount = amount.multiply(BlockConstant.SUN);
        if (amount.compareTo(BigDecimal.valueOf(Long.MAX_VALUE)) > 0) {
            throw new RuntimeException("TRX转账金额超出最大限额:" + amount);
        }
        long sendAmount = amount.longValue();
        return this.trxTx(fromAddress, fromPrk, toAddress, sendAmount);
    }

    /**
     * trx交易签离线签名 交易广播之后需要判断是否成功
     * 关于trx转账说明：如果收款地址未激活，则会额外消耗0.1trx激活地址，实际转账金额=amount + 0.1trx  实际收款金额=amount
     * trx转账会消耗带宽，如果带宽不够，则会消耗0.1TRX作为手续费
     *
     * @param fromAddress 转账地址,可以不需要此参数,因为有私钥
     * @param fromPrk     转账地址私钥
     * @param toAddress   收款地址 base58check格式
     * @param amount      转账金额 单位Sun  1 trx = 1000000 Sun
     * @return
     */
    public BroadcastResponse trxTx(String fromAddress, String fromPrk, String toAddress, long amount) {
        byte[] privateBytes = ByteArray.fromHexString(fromPrk);  //转账地址私钥
        ECKey ecKey = ECKey.fromPrivate(privateBytes);
        byte[] fromAddressBytes = ecKey.getAddress();
        byte[] toAddressBytes = this.base58Check2Hex(toAddress);
        //获取最新区块信息 用于构建交易
        TrxBlock nowBlock = this.getNowBlock();
        TrxRawData rawData = nowBlock.getBlockHeader().getRawData();
        long timestamp = rawData.getTimestamp();                //时间戳
        long blockHeight = rawData.getNumber();                 //区块号
        byte[] blockHash = Hex.decode(nowBlock.getBlockId());   //区块哈希
        Protocol.Transaction transaction = this.createTransaction(fromAddressBytes, toAddressBytes, amount, timestamp, blockHeight, blockHash);
        byte[] bytes = transaction.toByteArray();
        //交易签名
        byte[] signBytes;
        try {
            signBytes = this.signTransaction2Byte(bytes, privateBytes);
        } catch (Exception e) {
            log.error("交易签名失败 from={}  to={}  amount={}", fromAddress, toAddress, amount);
            throw new RuntimeException("TRX交易签名失败");
        }
        String signHex = Hex.toHexString(signBytes);
        log.info("交易签名结果={}", signHex);
        //广播交易
        String result = this.broadcastTx2(signHex);
        return JsonUtils.convertValue(result, BroadcastResponse.class);
    }

    public Protocol.Transaction createTransaction(byte[] from, byte[] to, long amount, long blockTimestamp, long blockHeight, byte[] blockHash) {
        Protocol.Transaction.Builder transactionBuilder = Protocol.Transaction.newBuilder();
        Protocol.Transaction.Builder builder = Protocol.Transaction.newBuilder();
        Protocol.Transaction.Contract.Builder contractBuilder = Protocol.Transaction.Contract.newBuilder();
        BalanceContract.TransferContract.Builder transferContractBuilder = BalanceContract.TransferContract.newBuilder();
        transferContractBuilder.setAmount(amount);
        ByteString bsTo = ByteString.copyFrom(to);
        ByteString bsOwner = ByteString.copyFrom(from);
        transferContractBuilder.setToAddress(bsTo);
        transferContractBuilder.setOwnerAddress(bsOwner);
        try {
            Any any = Any.pack(transferContractBuilder.build());
            contractBuilder.setParameter(any);
        } catch (Exception e) {
            return null;
        }
        contractBuilder.setType(Protocol.Transaction.Contract.ContractType.TransferContract);
        transactionBuilder.getRawDataBuilder().addContract(contractBuilder)
                .setTimestamp(System.currentTimeMillis())
                .setExpiration(blockTimestamp + 10 * 60 * 60 * 1000);
        Protocol.Transaction transaction = transactionBuilder.build();
        return this.setReference(transaction, blockHeight, blockHash);
    }

    private byte[] signTransaction2Byte(byte[] transaction, byte[] privateKey) throws InvalidProtocolBufferException {
        ECKey ecKey = ECKey.fromPrivate(privateKey);
        Protocol.Transaction transaction1 = Protocol.Transaction.parseFrom(transaction);
        byte[] rawdata = transaction1.getRawData().toByteArray();
        byte[] hash = Sha256Sm3Hash.hash(rawdata);
        byte[] sign = ecKey.sign(hash).toByteArray();
        return transaction1.toBuilder().addSignature(ByteString.copyFrom(sign)).build().toByteArray();
    }

    /**
     * 获取TRC20代币余额
     *
     * @param address         trx地址 base58check格式
     * @param contractAddress 代币合约地址  base58check格式
     * @return 地址代币余额
     */
    public BigDecimal getTrc20Balance(String address, String contractAddress) {
        Map<String, Object> params = new HashMap<>(8);
        params.put("contract_address", this.base58Check2Hex2(contractAddress)); //TRC20合约地址 hex格式
        params.put("function_selector", "balanceOf(address)");   //固定写死 调用合约方法
        //parameter表示收款地址以及转币数量
        String addressHex = this.base58Check2Hex2(address);
        int length = addressHex.length();
        int zeroLength = 64 - length;
        StringBuffer sb = new StringBuffer("");
        for (int i = 0; i < zeroLength; i++) {
            sb.append("0");
        }
        sb.append(addressHex);
        String parameter = sb.toString();
        params.put("parameter", parameter);
        params.put("fee_limit", 100000000); //类似ERC20的gasLimit
        params.put("call_value", 0);    //固定为0，否则会转trx
        params.put("owner_address", addressHex);    //转账地址 hex格式
        try {
            String result = HttpUtil.doPost(TrxUrlClient.getTrxCLient() + "/wallet/triggersmartcontract", JsonUtils.writeValueAsString(params));
            log.info("trc20余额查询返回结果={}", result);
            TrxBalance trxBalance = JsonUtils.convertValue(result, TrxBalance.class);
            Boolean b = trxBalance.getResult().getResult();
            if (b != null && b) {
                List<Object> constantResult = trxBalance.getConstantResult();
                if (!CollectionUtils.isEmpty(constantResult)) {
                    String balance = constantResult.get(0).toString();
                    if (StringUtils.isNotBlank(balance)) {
                        BigInteger bal = new BigInteger(balance, 16);
                        return BigDecimal.valueOf(bal.longValue()).divide(TRX2SUN, 6, RoundingMode.HALF_DOWN);
                    }
                }
            }
        } catch (Exception e) {
            log.error("获取TRC20代币余额异常 contractAddress={}  address={} e={}", contractAddress, address, e);
        }
        return null;
    }

    public TransInfo sendTrc20(TransInfo request) {
        String prk = AESUtil.decrypt(request.getPrivateKey(), BlockConstant.AES_KEY);
        request.setPrivateKey(prk);
        BroadcastResponse response;
        try {
            log.info("USDT_TRC20提币交易即将执行转账操作 from={}  to={} amount={}", request.getFromAddress(), request.getToAddress(), request.getAmount());
            response = this.sendTrc20(request.getFromAddress(), request.getPrivateKey(), request.getToAddress(), request.getAmount(), BlockConstant.USDT_TRC20_ADDRESS);
            log.info("USDT_TRC20提币交易转账执行结果={}", response.toString());
            if (response.getResult()) {
                request.setTxHash(response.getTxId());
                request.setStatus(TxStateEnum.TO_BE_CONFIRMED.getStatus());
            } else {
                request.setStatus(TxStateEnum.FAIL.getStatus());
                request.setErrMsg(response.getMessage());
            }
        } catch (Exception e) {
            request.setStatus(TxStateEnum.FAIL.getStatus());
            request.setErrMsg(e.getMessage());
        }
        return request;
    }

    /**
     * 发送TRC20代币 精度 10^6
     *
     * @param fromAddress     转账地址
     * @param fromPrk         转账地址私钥
     * @param toAddress       收款地址
     * @param amount          转账数量 单位:TRX
     * @param contractAddress 合约地址
     * @return
     */
    public BroadcastResponse sendTrc20(String fromAddress, String fromPrk, String toAddress, BigDecimal amount, String contractAddress) {
        amount = amount.multiply(BlockConstant.SUN);
        if (amount.compareTo(BigDecimal.valueOf(Long.MAX_VALUE)) > 0) {
            throw new RuntimeException("TRX转账金额超出最大限额:" + amount);
        }
        long txAmount = amount.longValue();
        return this.trc20Tx(fromAddress, fromPrk, toAddress, txAmount, contractAddress, 1500000L);
    }

    /**
     * TRC20代币交易
     */
    public BroadcastResponse trc20Tx(String fromAddress, String fromPrk, String toAddress, long amount, String contractAddress, long canConsumedTrx) {
        TrxBlock nowBlock = this.getNowBlock();
        TrxRawData rawData = nowBlock.getBlockHeader().getRawData();
        long timestamp = rawData.getTimestamp();   //时间戳
        long blockHeight = rawData.getNumber();    //区块号
        byte[] blockHash = Hex.decode(nowBlock.getBlockId());   //区块哈希
        //构建TRC20交易
        Protocol.Transaction tx = this.createTrc20Tx(
                fromAddress,
                toAddress,
                amount,
                contractAddress,
                canConsumedTrx,
                timestamp,
                blockHeight,
                blockHash
        );
        //交易签名
        byte[] bytes;
        try {
            bytes = this.signTransaction2Byte(tx.toByteArray(), ByteArray.fromHexString(fromPrk));
        } catch (Exception e) {
            log.error("交易签名失败");
            throw new RuntimeException(e.getMessage());
        }
        //广播交易
        String result = this.broadcastTx2(Hex.toHexString(bytes));
        return JsonUtils.convertValue(result, BroadcastResponse.class);
    }

    /**
     * 构建TRC20转账交易,未签名,需要签名然后广播出去
     *
     * @param fromAddress          转账地址 base58check格式
     * @param toAddress            收款地址 base58check格式
     * @param trc20ContractAddress trc20合约地址 base58check格式
     * @param amount               转账数量 单位 sun 1trx=1000000sun
     * @param maxFee               能量带宽不足时 最多可消耗TRX 单位 sun 1trx=1000000sun
     * @param blockTimestamp
     * @param blockHeight
     * @param blockHash
     * @return
     */
    public Protocol.Transaction createTrc20Tx(String fromAddress, String toAddress, long amount, String trc20ContractAddress, long maxFee, long blockTimestamp, long blockHeight, byte[] blockHash) {
        byte[] fromBytes = this.base58Check2Hex(fromAddress);
        byte[] toBytes = this.base58Check2Hex(toAddress);
        Protocol.Transaction.Builder transactionBuilder = Protocol.Transaction.newBuilder();
        Protocol.Transaction.Contract.Builder contractBuilder = Protocol.Transaction.Contract.newBuilder();
        SmartContractOuterClass.TriggerSmartContract.Builder triggerSmartContract = SmartContractOuterClass.TriggerSmartContract.newBuilder();
        //设置合约地址
        triggerSmartContract.setContractAddress(ByteString.copyFrom(this.base58Check2Hex(trc20ContractAddress)));
        //设置转账地址
        ByteString bsOwner = ByteString.copyFrom(fromBytes);
        triggerSmartContract.setOwnerAddress(bsOwner);
        //构建data数据 即 parameter参数
        StringBuffer sb = new StringBuffer("");
        sb.append(TRC20_TRANSFER_HEX);

        String toAddressHex = Hex.toHexString(toBytes);
        int length = toAddressHex.length();
        int zeroLength = 64 - length;
        for (int i = 0; i < zeroLength; i++) {
            sb.append("0");
        }
        sb.append(toAddressHex);
        String amountHex = BigInteger.valueOf(amount).toString(16);
        zeroLength = 64 - amountHex.length();
        for (int i = 0; i < zeroLength; i++) {
            sb.append("0");
        }
        sb.append(amountHex);
        String data = sb.toString();
        byte[] bytes = ByteArray.fromHexString(data);
        ByteString bytesStr = ByteString.copyFrom(bytes);
        triggerSmartContract.setData(bytesStr);
        try {
            Any any = Any.pack(triggerSmartContract.build());
            contractBuilder.setParameter(any);
        } catch (Exception e) {
            return null;
        }
        contractBuilder.setType(Protocol.Transaction.Contract.ContractType.TriggerSmartContract);
        Protocol.Transaction.raw raw = transactionBuilder.getRawDataBuilder()
                .addContract(contractBuilder)
                .setTimestamp(System.currentTimeMillis())
                .setExpiration(blockTimestamp + 10 * 60 * 60 * 1000)
                .setFeeLimit(maxFee)  //设置能量带宽不足时 最多可消耗TRX 单位 sun
                .build();
        Protocol.Transaction transaction = transactionBuilder
                .setRawData(raw)
                .build();
        return this.setReference(transaction, blockHeight, blockHash);
    }

    /**
     * 获取地址信息
     *
     * @param address base58格式地址
     * @return TrxAddress
     */
    public TrxAddress getAddressInfo(String address) {
        Map<String, Object> params = new HashMap<>(1);
        params.put("address", this.base58Check2Hex2(address));
        String result = HttpUtil.doPost(TrxUrlClient.getTrxCLient().getRpcServerUrl() + "/wallet/getaccount", JsonUtils.writeValueAsString(params));
        if (null == result || "{}".equals(result)) {
            return new TrxAddress();
        }
        return JsonUtils.convertValue(result, TrxAddress.class);
    }

    public static void main(String[] args) {
        //主网地址信息
        String httpUrl = "http://8.210.211.252:8090";
        //        TrxBlock nowBlock = getNowBlock();
        //        System.out.println(nowBlock.getBlockHeader().getRawData().getNumber());

        String from = "TPrBzES5eBN2L3S9vjUPc4U1J7oSuutZt8";
        String fromPrk = "5f62a647ae9a36d437d195b84e3d59fd01e563ac8a6112edee36469e097a62e2";
        String to = "TFwtVK7D7b5nydbFTEJjS8mRYS2eHbokBN";
        String contractAddress = BlockConstant.USDT_TRC20_ADDRESS;
        BigDecimal amount = new BigDecimal("1000000000");

        TrxService trxService = new TrxService();
        //        TrxAddress addressInfo = trxService.getAddressInfo(from);
        //        System.out.println(addressInfo.getBalance());

        //        BigDecimal trc20Balance = trxService.getTrc20Balance(from, contractAddress);
        //        System.out.println(trc20Balance);

        //TRX转账交易
        //        BroadcastResponse broadcastResponse = trxService.sendTrx(from, fromPrk, to, amount);
        //        System.out.println(broadcastResponse.getTxId());
        //        System.out.println(broadcastResponse.toString());

        //USDT_TRC20转账交易
        //        BroadcastResponse result = trxService.sendTrc20(from, fromPrk, to, amount, contractAddress);
        //        System.out.println(result.getTxId());
        //        System.out.println(result.toString());
    }

}
